﻿using System.Collections.Generic;
using System.Windows.Forms;
using BadgeManager.Controller;
using BadgeManager.Model;

namespace Badge_Manager.View
{
    public partial class frmDisponibilitaAule : Form
    {
        private Utente user;

        public List<Attivita> Attivita { get; set; }

        public List<Stanza> Stanze { get; set; }

        public frmDisponibilitaAule(Utente utente)
        {
            InitializeComponent();
            this.user = utente;
            getCombo();
            getElencoAule();
            this.cmbAule.SelectedIndexChanged += new System.EventHandler(this.cmbAule_SelectedIndexChanged);
            this.cmbFiltro.SelectedIndexChanged += new System.EventHandler(this.cmbFiltro_SelectedIndexChanged);
        }

        private void getCombo()
        {
            cmbFiltro.Items.Add("Disponibili");
            cmbFiltro.Items.Add("Non disponibili");
            cmbFiltro.SelectedIndex = 0;

            cmbAule.DataSource = new ctrlStanza().SelectAll();
            if (cmbAule.Items.Count > 0)
            { cmbAule.SelectedIndex = 0; }
        }

        private void getElencoAule()
        {
            if (cmbFiltro.SelectedIndex == 0)
                Attivita = new ctrlStanza()
                    .SelezionaAuleImpegnate(ctrlStanza.AulaImpegnata.Impegnata, (Stanza)cmbAule.SelectedItem);
            else
                Attivita = new ctrlStanza()
                    .SelezionaAuleImpegnate(ctrlStanza.AulaImpegnata.Libera, (Stanza)cmbAule.SelectedItem);

            gridAule.DataSource = null;
            gridAule.DataSource = Attivita;

            gridAule.Columns["Id"].Visible = false;
        }

        private void cmbFiltro_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            getElencoAule();
        }

        private void cmbAule_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            getElencoAule();
        }
    }
}